package com.example.springboot.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 功能：分装Result对象  返回码 数据 错误信息
 * 作者：陈雷
 * 日期：2024/10/17 21:26
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder

public class Result {
    public static final String SUCCESS_CODE = "200";
    public static final String ERROR_CODE = "500";
    public static final String ERROR_MSG = "404";
    private String code;
    private String msg;
    private Object data;

    public static Result success() {
        return new Result(SUCCESS_CODE, "请求成功", null);
    }

    public static Result success(Object data) {
        return new Result(SUCCESS_CODE, "请求成功", data);
    }

    public static Result error(String msg) {
        return new Result(ERROR_CODE, msg, null);
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error() {
        return new Result(ERROR_CODE, "系统错误", null);
    }

}